package nz.co.doherty.gwtpbreadcrumbs.server.handler.customer;

import nz.co.doherty.gwtpbreadcrumbs.shared.entity.Customer;
import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.customer.CustomerListAction;
import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.customer.CustomerListResult;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.philbeaudoin.gwtp.dispatch.server.ExecutionContext;
import com.philbeaudoin.gwtp.dispatch.server.actionHandler.ActionHandler;
import com.philbeaudoin.gwtp.dispatch.shared.ActionException;

public class CustomerListHandler implements ActionHandler<CustomerListAction, CustomerListResult> {
	
	@Override
	public CustomerListResult execute(CustomerListAction action,
			ExecutionContext context) throws ActionException {

		Objectify ofy = ObjectifyService.begin();
		return new CustomerListResult(ofy.query(Customer.class).list());

	}

	@Override
	public void undo(CustomerListAction action, CustomerListResult result,
			ExecutionContext context) throws ActionException {
		// TODO Auto-generated method stub

	}

	@Override
	public Class<CustomerListAction> getActionType() {
		return CustomerListAction.class;
	}

}
